﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics.OpenGL;
using System.Drawing;
using System.Drawing.Imaging;

namespace MyOpenGame
{
    public class Texture
    {
        private static int _background;
        private static int _reideer;
        private static int _source;
        private static int _sourceSelected;
        private static int _building;
        private static int _buildingSelected;
        private static int _ball;
        private static int _inventory;
        

        public static void setBackground(int textureId)
        {
            _background = textureId;
        }

        public static int getBackground()
        {
            return _background;
        }

        public static void setReideer(int textureId)
        {
            _reideer = textureId;
        }

        public static int getReideer()
        {
            return _reideer;
        }

        public static void setSource(int textureId)
        {
            _source = textureId;
        }

        public static int getSource()
        {
            return _source;
        }

        public static void setSourceSelected(int textureId)
        {
            _sourceSelected = textureId;
        }

        public static int getSourceSelected()
        {
            return _sourceSelected;
        }

        public static void setBuilding(int textureId)
        {
            _building = textureId;
        }

        public static int getBuilding()
        {
            return _building;
        }

        public static void setBuildingSelected(int textureId)
        {
            _buildingSelected = textureId;
        }

        public static int getBuildingSelected()
        {
            return _buildingSelected;
        }

        public static void setBall(int textureId)
        {
            _ball = textureId;
        }

        public static int getBall()
        {
            return _ball;
        }

        public static void setInventory(int textureId)
        {
            _inventory = textureId;
        }

        public static int getInventory()
        {
            return _inventory;
        }

        public static int Load(Bitmap bmp)
        {
            //if (String.IsNullOrEmpty(filename))
            //    throw new ArgumentException(filename);

            int id = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, id);

            //Bitmap bmp = new Bitmap(filename);
            BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

            bmp.UnlockBits(bmp_data);

            // We haven't uploaded mipmaps, so disable mipmapping (otherwise the texture will not appear).
            // On newer video cards, we can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
            // mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            return id;
        }
    }
}
